package com.cqrt.mapper;


import com.alibaba.fastjson.JSONObject;
import com.cqrt.dto.TemplateDTO;
import com.cqrt.entity.RTPlanJobLinkDO;
import com.cqrt.entity.RTTemplateAttrLinkDO;
import com.cqrt.entity.RTTemplateStatusDO;
import com.cqrt.vo.ProjectManagerVO;
import com.hustcad.plm.rpm.model.dto.admin.TyppmProjectDTO;
import com.hustcad.plm.rpm.model.entity.admin.TyppmProject;
import com.hustcad.plm.rpm.model.entity.admin.TyppmProjectTemplate;
import com.hustcad.plm.rpm.model.vo.calendar.CalendarWeekDayVO;
import com.hustcad.plm.rpm.model.vo.project.ProjectTemplateVO;
import com.ty.basic.entity.org.UserDO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Repository
public interface RTProjectsTemplateMapper {

    List<TemplateDTO> batchSelectTemplatesWithFolder(@Param("templateIds") List<String> templateIds);

    void batchInsert(@Param("templateAttrLinkDos") List<RTTemplateAttrLinkDO> templateAttrLinkDos);

    TyppmProjectDTO queryTemplateAttrById(String oid);

    @Select("select oid from ty_pj_projecttemplate where projectoid= TO_NUMBER(#{oid})")
    BigInteger selectTemplateIdByOid(String oid);

    void batchDeleteWithLink(BigInteger oid);

    void batchInsertLink(@Param("rtPlanJobLinkDOS")List<RTPlanJobLinkDO> rtPlanJobLinkDOS);

    BigInteger getPlanById(String projectId);

    void unLockStatusById(BigInteger oid);

    void lockStatusById(@Param("oid")BigInteger oid, @Param("user")UserDO user);

    List<BigInteger> queryCalendarById(@Param("projectList")List<String> projectList);

    List<TyppmProjectTemplate> queryProjectTemplateListByCondition(@Param("keys")List<String> keys);

    void insertTemplate(RTTemplateStatusDO rtTemplateStatusDO);

    Integer existsTemplateStatus(BigInteger oid);

    @Update("update RT_PRJ_TEMPLATE_STATUS set status=#{status}  where TEMPLATE_ID=#{oid}")
    void updateStatusById(@Param("oid")BigInteger oid, @Param("status")String status);

    @Delete("delete from RT_PRJ_TEMPLATE_STATUS where TEMPLATE_ID=TO_NUMBER(#{oid})")
    void deleteStatusById(String oid);

    void updateTemplateName(@Param("oid")BigInteger oid, @Param("status")String status);

    void updateProjectsByTemplateId(@Param("oid")BigInteger oid, @Param("status")String status);

    void updatePlansByTemplateId(@Param("oid")BigInteger oid, @Param("status")String status);

    void restoreTemplateName(BigInteger oid,String status);

    void restoreProjectsByTemplateId(BigInteger oid,String status);

    void restorePlansByTemplateId(BigInteger oid,String status);

    List<BigInteger> selectTemplateIdByCondition(@Param("pushMode")String pushMode, @Param("developmentLevel")String developmentLevel);

    @MapKey("OID")
    Map<String, Map<String,String>> batchSelectDevelopmentByOids(@Param("oidList")List<String> oidList);

    List<String> selectExistingKeys(@Param("keyPairs")List<Map<String, BigInteger>> keyPairs);

    void deleteTemplateById(@Param("templateIds")List<BigInteger> templateIds);

    @Select("select * from RT_PRJ_TEMPLATE_STATUS where TEMPLATE_ID=TO_NUMBER(#{oid})")
    RTTemplateStatusDO selectTemplateByOid(String oid);

    Integer existExecuteProject(@Param("projectList")List<String> projectList);

    @Select("select oid from ty_sys_calendar where  parentoid =TO_NUMBER(#{projectId})")
    BigInteger selectCalendarById(@Param("projectId")String projectId);

    List<CalendarWeekDayVO> batchSelectWeekById(@Param("calendarIds")List<String> calendarIds);

    List<TyppmProject> batchSelectNameById(@Param("projectList")List<String> projectList);

    @Select("select TO_CHAR(oid) from TY_PJ_PROJECTTEMPLATE where PROJECTOID=TO_NUMBER(#{projectId})")
    String selectTemplateById(String projectId);

    @Select("select PROJECTOID from TY_PJ_PROJECTTEMPLATE where oid=TO_NUMBER(#{templateOid})")
    BigInteger selectProjectById(String templateOid);

    BigInteger getLinkOId(@Param("uId")String uId,@Param("templateOid") String templateOid);

    List<BigInteger> batchSelectObjectMessageLinkList(@Param("paramPairs")List<Map<String, String>> paramPairs);

    void batchDeleteMessageLink(@Param("uIds")Set<String> uIds);

    @MapKey("templateOid")
    Map<String, Map<String,String>> selectPlanOidByTemplateOids(@Param("templateOids")List<BigInteger> templateOids);

    List<BigInteger> selectValidRootOids(@Param("planOIDList")List<BigInteger> planOIDList, @Param("name")String name);

    @Select("select name from TY_PJ_PLANACTIVTE where OID=TO_NUMBER(#{planActiveOID})")
    String selectPlanNameById(String planActiveOID);

    List<TyppmProjectTemplate> queryTemplateListByCondition(@Param("templateDTO") TemplateDTO templateDTO);

    List<TyppmProjectTemplate> selectAttrByIds(@Param("oids") List<String> oids);

    TyppmProjectDTO selectTempAttr(String projectOID);

    //根据计划OID查询模板OID
    List<BigInteger> selectTemplateValueByOId(String templateOid);

    List<ProjectManagerVO> queryProjectByManger(@Param("manger") String manger,@Param("nameList") List<String> nameList, @Param("numberList") List<String> numberList);

    List<ProjectManagerVO> selectProjectByMember(@Param("member")String member,@Param("projectName") String projectName,@Param("projectNumber") String projectNumber,@Param("thisYear")String thisYear);

    BigInteger selectIsTemplate(BigInteger planOid);

}